<div class="list-body">
	 <form id="userprotocol-search-form" data-toggle="ajaxform" data-options="{beforeSubmit:setUserprotocolSearchValue,url: '/userProtocol/list',validate: false,okalert:false,loadingmask: true,okCallback:getUserprotocolListData}">
	 	<div class="row">
			<div class="search-input">
        		<input type="text"  id="userproto-name-input" placeholder="输入协议名称" onblur="Trim(this,this.value)">
        		<input type="text" name="name" id="userProtocolNameDisNone" style="display: none;">
        		{{#if roleinfo.role}}
        			<input type="text"  id="userproto-uname-input" placeholder="输入所属用户" onblur="Trim(this,this.value)">
        			<input type="text" name="uname" id="userProtocolUnameDisNone" style="display: none;">
				{{/if}}
        		<div style="display: none;">
					<input type="text" name="pageCurrent" value="1">
        			<input type="text" name="pageSize" value="12">
        		</div>
        		<button type="submit" class="search-btn" data-icon="search"></button>
    		</div>
    		<a class="add-btn userProtocol-btn" onclick="dialog_userProtocol_addPage()"><i class="fa fa-plus-square-o"></i><span>添加私有协议</span></a>
		</div>
		
	</form>
	<ul class="row list-content userProtocol-list-content">
	
	</ul>
	<div id="pagination_userproto" style="text-align: center;display: none; "></div>
</div>

<script type="text/javascript">
	$(function(){
		 var userprotocolTotalNum ;
		pagination_callback(1,12,1);
		if('{{roleinfo.role}}'){
			$('.userProtocol-btn').addClass('disable');
			$('.userProtocol-btn').removeAttr('onclick');
		}else{
	      $('.userProtocol-btn').removeClass('disable');
	      $('.userProtocol-btn').attr('onclick');
	    }
		$("input").placeholder();

	})
	function setUserprotocolSearchValue(from){
		$('#userproto-name-input').val()!='输入协议名称' ? $('#userProtocolNameDisNone').val($('#userproto-name-input').val()) : $('#userProtocolNameDisNone').val('');
      	if('{{roleinfo.role}}'){
       	 	$('#userproto-uname-input').val()!='输入所属用户' ? $('#userProtocolUnameDisNone').val($('#userproto-uname-input').val()) : $('#userProtocolUnameDisNone').val('');
      	}
      	return true;
	}
	function getUserprotocolListData(json, options){
		$('#pagination_userproto').pagination('destroy')
    	$('#pagination_userproto').pagination({
	   	 	total:json.totalRow, pageSize:12, callback:pagination_callback
		})
    	userprotocolTotalNum=json.totalRow;
    	set_list(json);
    	if(json.totalRow<=12){
        	$("#pagination_userproto").css("display","none");
        }else{
        	$("#pagination_userproto").css("display","block");
        }
	}
	function pagination_callback(pageCurrent, pageSize,num) {
		var	userProtocolUname;
		var userProtocolName=$("#userProtocolNameDisNone").val();
		if('{{roleinfo.role}}'){
			userProtocolUname=$("#userProtocolUnameDisNone").val();
		}
	    BJUI.ajax('doajax', {
	        url: '/userProtocol/list',
	        loadingmask: true,
	        data: {pageCurrent:pageCurrent, pageSize:pageSize,name:userProtocolName,uname:userProtocolUname},
	        okCallback: function(json, options) {
	        	if(json!=''){
	        		set_list(json);
	        	}
	        	if(num==1){
	            	 $('#pagination_userproto').pagination({
			   	 		total:json.totalRow, pageSize:12, callback:pagination_callback
					}) 
	            }
            	userprotocolTotalNum=json.totalRow;
            	if(json.totalRow>pageSize){
	            	$("#pagination_userproto").css("display","block");
	            }else{
	            	$("#pagination_userproto").css("display","none");
	            }
	            
	        }
	    })
	}
	function set_list(json){
		$('.userProtocol-list-content').empty();
		var btnArr=[
			{title:"编辑",icon:"fa fa-edit",fun:"userProtocol_editPage"},
			{title:"详情",icon:"fa fa-list-alt",fun:"userProtocol_detailsPage"},
			{title:"删除",icon:"fa fa-trash-o",fun:"userProtocol_del"}
		];
		$('.userProtocol-list-content').setList(json.list,btnArr,'fa-file-o');
	
	}
	function dialog_userProtocol_addPage(){
		BJUI.dialog({
			id:"userProtocolAddPage",
			url:"/userProtocol/addPage",
			title:"添加私有协议",
			type:"post",
			width:"860",
			height:"700",
			mask:true,
			maxable:false,
			resizable:false
		})
	}
	function userProtocol_editPage(obj){
		var id=$(obj).parent().parent().prevAll("#item-id").text();
		BJUI.dialog({
			id:"userProtocolEditPage",
			url:"/userProtocol/editPage",
			title:"编辑私有协议",
			type:"post",
			data:{"id":id},
			width:"860",
			height:"700",
			mask:true,
			maxable:false,
			resizable:false

		})
	}
	function userProtocol_detailsPage(obj){
		var id=$(obj).parent().parent().prevAll("#item-id").text();
		BJUI.dialog({
			id:"userProtocolDetails",
			url:"/userProtocol/details",
			title:"用户私有协议",
			type:"post",
			data:{"id":id},
			width:"620",
			height:"600",
			mask:true,
			maxable:false
		})
		
	}
	function userProtocol_del(obj){

		var id=$(obj).parent().parent().prevAll("#item-id").text();
		 BJUI.alertmsg('confirm', '确定要删除吗！', {
	        okCall: function() {
	            BJUI.ajax('doajax', {
				    url: '/userProtocol/del',
				    type:"post",
				    data:{"id":id},
				    loadingmask: true,
				    okCallback: function(json, options) {
				    		userprotocolTotalNum -=1;
                $('#pagination_userproto').pagination('destroy')
                $('#pagination_userproto').pagination({
            total:userprotocolTotalNum, pageSize:12, callback:pagination_callback
        });
                       pagination_callback(1,12,1);
                    }
				})
	        }
	    })
		
	}
</script>